package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.anno.AuthLogin;
import com.atguigu.tingshu.common.anno.CustomCache;
import com.atguigu.tingshu.common.constant.RedisConstant;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.user.service.UserInfoService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.bouncycastle.LICENSE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.ReactiveSubscription;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;

	@GetMapping("findUserById/{userId}")
	@CustomCache(cacheKey = RedisConstant.CACHE_USER_PREFIX + "#{#params[0]}")
	public Result<UserInfo> findUserById(@PathVariable Long userId) {
		return Result.ok(userInfoService.getById(userId));
	}

	@AuthLogin(required = false)
	@PostMapping("/userIsPaidTrack/{albumId}")
	public Result<Map<Long, Integer>> userIsPaidTrack(@PathVariable Long albumId, @RequestBody List<Long> trackIdList) {
		return Result.ok(userInfoService.userIsPaidTrack(albumId, trackIdList));
	}
	@AuthLogin
	@GetMapping("/findUserPaidTrackList/{albumId}")
	public Result<List<Long>> findUserPaidTrackList(@PathVariable Long albumId){
		return Result.ok(userInfoService.findUserPaidTrackList(albumId));
	}

	@AuthLogin
	@GetMapping("/isUserPaidAlbum/{albumId}")
	public Result<Boolean> isUserPaidAlbum(@PathVariable Long albumId){
		return Result.ok(userInfoService.isUserPaidAlbum(albumId));
	}

	@GetMapping("/updateVipExpireHandler")
	public Result<Void> updateVipExpireHandler(){
		userInfoService.updateVipExpireHandler();
		return Result.ok();
	}





}

